<template>
	<view class="cancel_order">
		<view class="title">
			<text>取消订单</text>
			<view class="close" @click="close">
				<image src="@/static/images/close.png"></image>
			</view>
		</view>
		<scroll-view scroll-y class="scroll_view">
			<view class="desc">
				<view class="head">温馨提示：</view>
				<view class="cell">
					<view>1.限时特价、预约资格等购买优惠可能一并取消</view>
					<view>2.如遇订单拆分，优惠卷将换成同价值积分返还</view>
					<view>3.支付券不予返还；支付优惠一并取消</view>
					<view>4.订单一旦取消，无法恢复</view>
				</view>
			</view>
			<view class="sub_title">请选择取消订单的原因（必选）：</view>
			<view class="list">
				<view class="item" v-for="(item,index) in list" @click="active=index">
					<image src="@/static/images/checked.png" v-if="active==index"></image>
					<image src="@/static/images/checked_no.png" v-else></image>
					<view>{{item}}</view>
				</view>
			</view>
		</scroll-view>
		<view class="cancel_btn">
			<view @click="submit">提交</view>
		</view>
	</view>
</template>

<script setup>
	import {
		orderInfo,
		orderCancel
	} from "@/request/api";
	const props = defineProps({
		id: [Number, String]
	});
	const emit = defineEmits(["close"]);

	import {
		ref
	} from "vue";
	const list = ref({});
	const active = ref("");
	const getDeta = async () => {
		let {
			cancel_reason
		} = await orderInfo({
			id: props.id
		});
		list.value = cancel_reason;
	};
	getDeta();
	const submit = async () => {
		await orderCancel({
			id: props.id,
			cancel_reason: active.value
		});
		uni.$uv.toast("操作成功");
		setTimeout(() => emit('close'), 1500);
	};
	const close = () => emit('close');
</script>

<style scoped lang="scss">
	.cancel_order {
		width: 100%;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		box-sizing: border-box;
		overflow: hidden;
		background: #FFFFFF;

		.title {
			text-align: center;
			color: #222222;
			font-size: 36rpx;
			font-weight: bold;
			padding: 40rpx 0 50rpx;
			box-sizing: border-box;
			position: relative;

			.close {
				position: absolute;
				right: 25rpx;
				top: 50%;
				transform: translateY(-50%);
				z-index: 2;

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}

		.scroll_view {
			height: 800rpx;
			padding: 0 25rpx;
			box-sizing: border-box;

			.desc {
				width: 100%;
				padding: 25rpx 30rpx 0;
				box-sizing: border-box;
				background: #F8F8F8;

				.head {
					color: #222222;
					font-size: 26rpx;
				}

				.cell {
					padding: 40rpx 0 50rpx;
					box-sizing: border-box;

					view {
						line-height: 36rpx;
						color: #222222;
						font-size: 26rpx;
					}
				}
			}

			.sub_title {
				color: #222222;
				font-size: 32rpx;
				font-weight: bold;
				padding-top: 86rpx;
			}

			.list {
				padding-bottom: 34rpx;
				box-sizing: border-box;

				.item {
					margin-top: 60rpx;
					display: flex;
					align-items: center;

					image {
						width: 40rpx;
						height: 40rpx;
					}

					view {
						color: #222222;
						font-size: 28rpx;
						padding-left: 24rpx;
						box-sizing: border-box;
					}
				}
			}
		}

		.cancel_btn {
			width: 100%;
			height: 180rpx;
			border-top: 4rpx solid #F8F8F8;
			padding: 0 30rpx 15rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			justify-content: flex-end;

			view {
				width: 100%;
				height: 78rpx;
				line-height: 78rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 30rpx;
				font-weight: bold;
				border-radius: 10rpx;
				background: #CA1C1D;
			}
		}
	}
</style>